package org.the.gsdo.server;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.env.Environment;

@Configuration
@PropertySource("classpath:/org/the/gsdo/server/gsdo.properties")
@ComponentScan(
		// scan by class names
		basePackageClasses = {
				GreetingManager.class,
				LogAspect.class
		})
@EnableAspectJAutoProxy(proxyTargetClass=true)
public class ApplicationConfiguration implements ApplicationContextAware {

	@Autowired
	private Environment env;

	@Override
	public void setApplicationContext(ApplicationContext context)
			throws BeansException {
		System.out.println("setApplicationContext / " + context);
		BeanProvider.setContext(context);
	}

	@Bean(name="version")
	public String getVersion() {
		return env.getProperty("gsdo.version");
	}

}
